package com.vito.dcs.water.waterDataLog.action;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vito.base.authoriza.action.BaseAction;
import com.vito.base.authoriza.cache.SessionMap;
import com.vito.base.authoriza.model.UserModel;
import com.vito.dcs.water.waterDataLog.model.DataWaterBlenderLogModel;
import com.vito.dcs.water.waterDataLog.service.DataWaterBlenderLogService;
import com.vito.base.model.Result;
import com.vito.base.exception.ParamErrorException;
import com.vito.base.model.ResMsg;
import com.vito.base.util.*;

/**
 * 水稳搅拌站原始数据表请求控制器
 * @author  fangj
 * @version 0.1.1
 * @date    2019-4-12 14:21:46
 */
@Controller
@RequestMapping("/dcs/water/waterDataLog")
public final class DataWaterBlenderLogAction extends BaseAction {
	
	private static final Logger log = LoggerFactory.getLogger(DataWaterBlenderLogAction.class);
	
	@Reference
	private DataWaterBlenderLogService datawaterblenderlogServiceImpl;
	
	/**
	 * 保存水稳搅拌站原始数据表
	 * @author  fangj  
	 * @version 创建时间：2019-4-12 14:21:46
	 * @return  code:状态码 ,msg:提示信息
	 * @param   datawaterblenderlog 需要保存的水稳搅拌站原始数据表对象
	*			3434
	 */
	@RequestMapping("saveDataWaterBlenderLog")
	@ResponseBody
	public Result saveDataWaterBlenderLog(@RequestBody DataWaterBlenderLogModel datawaterblenderlog){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(datawaterblenderlog, "水稳搅拌站原始数据表不能为空");
			datawaterblenderlogServiceImpl.saveDataWaterBlenderLog(datawaterblenderlog);
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.SAVESUC);
		}catch(Exception ex){
			log.error("保存失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 分页查询水稳搅拌站原始数据表
	 * @author  fangj  
	 * @version 创建时间：2019-4-12 14:21:46
	 * @return  {code:0,data:{total:20,rows:[{}...]}}
	 * @param   datawaterblenderlog 依靠水稳搅拌站原始数据表对象分页查询
	 *          <li>pageNo default 1</li>
	 *          <li>pageSize default 15</li>
	 */
	@RequestMapping("queryDataWaterBlenderLogByPage")
	@ResponseBody
	public Result queryDataWaterBlenderLogByPage(DataWaterBlenderLogModel datawaterblenderlog){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(datawaterblenderlog, "水稳搅拌站原始数据表不能为空");
			res.setData(datawaterblenderlogServiceImpl.queryAllByPage(datawaterblenderlog));
			res.setCode(Result.CODE_OK);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 查询一条水稳搅拌站原始数据表
	 * @author  fangj  
	 * @version 创建时间：2019-4-12 14:21:46
	 * @return  {code:0,data:{...}}
	 * @param   datawaterblenderlog 依靠水稳搅拌站原始数据表对象查询
	 */
	@RequestMapping("queryDataWaterBlenderLog")
	@ResponseBody
	public Result queryDataWaterBlenderLog(DataWaterBlenderLogModel datawaterblenderlog){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			res.setData(datawaterblenderlogServiceImpl.query(datawaterblenderlog));
			res.setCode(Result.CODE_OK);
		}catch(Exception ex){
			log.error("查询失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
		
	/**
	 * 更新水稳搅拌站原始数据表对象
	 * @author  fangj  
	 * @version 创建时间：2019-4-12 14:21:46
	 * @return  {code:0,data:10}
	 * @param   datawaterblenderlog 依靠水稳搅拌站原始数据表对象的id变更传入的其他属性值
	 *		 	<li>Id:主键ID 不能为null 或空字符串</li>
	 */
	@RequestMapping("updateDataWaterBlenderLog")
	@ResponseBody
	public Result updateDataWaterBlenderLog(@RequestBody DataWaterBlenderLogModel datawaterblenderlog){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(datawaterblenderlog.getId(),"主键ID不能为空");
			res.setData(datawaterblenderlogServiceImpl.update(datawaterblenderlog));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.UPDSUC);
			
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("更新失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
	/**
	 * 删除水稳搅拌站原始数据表对象
	 * @author  fangj  
	 * @version 创建时间：2019-4-12 14:21:46
	 * @return  {code:0,data:10}
	 * @param   datawaterblenderlog 删除水稳搅拌站原始数据表对象的 checkeds 标识的id对应的数据
	 */
	@RequestMapping("deleteDataWaterBlenderLog")
	@ResponseBody
	public Result deleteDataWaterBlenderLog(DataWaterBlenderLogModel datawaterblenderlog){
		Result res = new Result();
		try{
			UserModel user = SessionMap.getObj();
			if(null == user){
				res.setCode(Result.CODE_LOGIN_REQUIRE);
				res.setMsg(ResMsg.MSG_LOGIN_NEED);
				return res;
			}
			Validata.isNullOrEmpty(datawaterblenderlog.getCheckeds(), "所选项不能为空");
			res.setData(datawaterblenderlogServiceImpl.delete(datawaterblenderlog));
			res.setCode(Result.CODE_OK);
			res.setMsg(ResMsg.DELCOM);
		}catch(ParamErrorException e){
			res.setMsg(e.getMessage());
			res.setCode(Result.CODE_ERROR);
		}catch(Exception ex){
			log.error("删除失败",ex);
			res.setCode(Result.CODE_ERROR);
			res.setMsg(ResMsg.EXECERR);
		}
		return res;
	}
	
}
